/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

#ifndef __WIND_MANAGER_H
#define __WIND_MANAGER_H

#include "LayerManager.h"

/*<-------Defines--------->*/
#define MAX_WIND_MEASUREMENTS 128
#define MAX_BARBS 10
/*<------End Defines------>*/

typedef struct _WindIconAlloc_t {
	char            color_str[32];
	GooCanvasItem  *station;
	GooCanvasItem  *calm;
	GooCanvasItem  *stem;
	GooCanvasItem  * barbs[MAX_BARBS];
	GooCanvasItem  *item;
	double         img_x;
	double         img_y;

	_WindIconAlloc_t() { 
		station = stem = calm = item = NULL; 
		img_x = img_y = NAN;
		for(int i=0; i<MAX_BARBS; i++)
			barbs[i] = NULL;
	}
} WindIconAlloc_t;

typedef struct _WindDataAlloc {
	GooCanvasItem  *wind_group;
	WindIconAlloc_t icons[MAX_WIND_MEASUREMENTS];
	WindData_t data[MAX_WIND_MEASUREMENTS];

	int first;
	int last;

	_WindDataAlloc() { 
		first = 0; 
		last = MAX_WIND_MEASUREMENTS;
		wind_group = NULL;
	}

} WindDataAlloc;

class WindManager : public LayerManager
{
	private:
		WindDataAlloc windValues[MAX_CLIENTS+1];
		float minRange; // in units of window pixels
		int   lastAdd;
		int   buffLength;

		GooCanvasItem *scale_item;
		GooCanvasItem *scale_item_h;
		GtkScale      *scale_widget;

	public:
		WindManager();
		~WindManager();

		bool received_data(int clientInd, uint8_t * buf);
		bool add_windData(int clientInd, WindData_t * wind);
		void create_wind_icon(int clientInd, unsigned int ind, float speed);

		void create_scale();
		static void scale_value_cb(GtkRange* range, gpointer func_data);

		virtual void init(GPSMap *map = NULL);
		virtual void updateMap();
		virtual void translate_from_zoomChange(double zoom_factor);
		virtual bool setShown(int setTo = -1);
};

#endif
